package com.ls.aicoderbackend.core.saver;

import cn.hutool.core.util.ObjUtil;
import com.ls.aicoderbackend.ai.model.MultiFileCodeResult;
import com.ls.aicoderbackend.exception.BusinessException;
import com.ls.aicoderbackend.exception.ErrorCode;
import com.ls.aicoderbackend.model.enums.CodeGenTypeEnum;

public class MultiFileSaveTemplate extends CodeFileSaveTemplate<MultiFileCodeResult>{
    @Override
    protected void saveFile(MultiFileCodeResult result, String baseDirPath) {
        writeToFile(baseDirPath, "index.html", result.getHtmlCode());
        writeToFile(baseDirPath, "style.css", result.getCssCode());
        writeToFile(baseDirPath, "script.js", result.getJsCode());
    }

    @Override
    protected CodeGenTypeEnum getBizType() {
        return CodeGenTypeEnum.MULTI_FILE;
    }

    @Override
    protected void validateInput(MultiFileCodeResult result) {
        super.validateInput(result);
        if (ObjUtil.isNull(result.getHtmlCode())) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "html结果为空");
            }
        }
}
